package com.glory.wxelectricitypda.activity;

import com.glory.wxelectricitypda.base.Constant;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.pda.platform.ui.ui_pdaplatform.base.FreeUI_BaseActivity;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_TabCountEntity;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_TabIndexGridEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_LogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StringUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class HomeActivity extends FreeUI_BaseActivity {


    @Override
    protected int getLayoutResId() {
        return 0;
    }

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {
        try {
            InputStream inputStream = getApplicationContext().getResources().getAssets().open("json.txt");
            String json = FreeApi_StringUtils.getString(inputStream);
            List<FreeUI_TabCountEntity> entity = new Gson().fromJson(json, new TypeToken<List<FreeUI_TabCountEntity>>() {
            }.getType());
            goHomeActivity(0, FreeApi_StaticMembers.THEME_SINGLE_SKY_BLUE, getBytesList(filter(entity)));
            this.finish();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return null;
    }

    private List<FreeUI_TabCountEntity> filter(List<FreeUI_TabCountEntity> entity){
        if (Constant.AUTHORITY_LIST.size() != 0) {
            for (int i = entity.get(0).getTabIndexGridEntityList().size() - 1; i >= 0; i--) {
                if (!Constant.AUTHORITY_LIST.contains(entity.get(0).getTabIndexGridEntityList().get(i).getText())) {
                    entity.get(0).getTabIndexGridEntityList().remove(entity.get(0).getTabIndexGridEntityList().get(i));
                }
            }
        }
//        Iterator it = entity.iterator();
//        while (it.hasNext()) {
//            FreeUI_TabIndexGridEntity item = (FreeUI_TabIndexGridEntity) it.next();
//            if (!Constant.AUTHORITY_LIST.contains(item.getText())) {
//
//                it.remove();
//
//            }
//        }

        return entity;
    }
}
